<template>
  <nav class="navigation-bar">
    <div class="logo-section">
      <img :src="blogInfo?.logo" alt="{{blogInfo.title}}" v-if="blogInfo?.logo" >
      <h1>{{ blogInfo.name || 'Blog' }}</h1>
    </div>
    <div class="nav-links">
      <NavBar/>
    </div>
    <div class="search-section">
      <SearchBar class="section-search-bar"/>
      <ThemeSwitch class="section-theme"/>
      <AuthSection class="section-auth"/>
    </div>
  </nav>
</template>

<script setup>
import {useUserStore} from '@stores/userStore.js'
import SearchBar from '@/components/nav/SearchBar.vue'
import ThemeSwitch from '@/components/nav/ThemeSwitch.vue'
import AuthSection from '@/components/nav/AuthSection.vue'
import NavBar from '@/components/nav/NavBars.vue'

const store = useUserStore();
const router = useRouter();
const blogInfo = ref('');
const getBlogInfo = async () => {
  const res = await axios.get('/api/blog/siteinfo/blogheader/', {requiresAuth: false});
  blogInfo.value = res.data;
}

// 生命周期挂载时触发
onMounted(() => {
  store.checkLoginStatus(); // 检查登录状态
  getBlogInfo(); // 获取网站logo和名称
})
</script>

<style scoped>
/* 导航栏样式 */
.navigation-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  height: 45px;
  background-color: var(--nav-bg-color, #393d49);
  border-bottom: 1px solid #5FB878;
  color: var(--text-color, #ffffff);
  border-radius: 8px 8px 0px 0px;
  z-index: 999;
}

/* Logo部分 */
.logo-section {
  display: flex;
  align-items: center;
  width: auto;
}

.logo-section h1 {
  margin: 0;
  padding: 0;
  font-size: 22px;
  font-weight: bold;
  color: var(--text-color, #ffffff);
}

.logo-section img {
  max-width: 120px;
  max-height: 40px;
  min-height: 20px;
  margin: 0 10px;
  border-radius: 8px;
  object-fit: cover;
}

.nav-links {
  display: flex;
  list-style: none;
  align-items: center;
  margin: 0 auto;
}

.search-section {
  display: flex;
  align-items: center;
  padding: 5px;
}

/* 响应式处理 */
@media (max-width: 992px) {
  /* 调换 nav-links 和 search-section 的顺序 */
  .logo-section h1 {
    font-size: 20px;
  }

  .nav-links {
    order: 2; /* 设置次序 2 */
    justify-content: flex-end;
  }

  .search-section {
    order: 1; /* 设置次序 1 */
    width: 80%;
    justify-content: center;
  }

  .section-search-bar {
    order: 1;
  }

  .section-theme {
    order: 3;
  }

  .section-auth {
    order: 2;
  }
}

@media (max-width: 768px) {
  .logo-section h1 {
    font-size: 18px;
  }

  .search-section {
    width: auto;
  }
}

@media (max-width: 576px) {
  .logo-section {
    text-align: center;
  }

  .search-section {
    margin: 0 auto;
  }

  .section-search-bar {
    display: none;
  }

  .section-theme {
    display: none;
  }
}

@media (max-width: 480px) {
  .section-search-bar {
    display: none;
  }
}
</style>
